<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Delaying allocation when a node leaves | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'delayed-allocation.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/delayed-allocation.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/delayed-allocation.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/delayed-allocation.html" rel="nofollow" target="_blank">../en/delayed-allocation.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="index-modules.html">Index modules</a></span>
»
<span class="breadcrumb-link"><a href="index-modules-allocation.html">Index Shard Allocation</a></span>
»
<span class="breadcrumb-node">Delaying allocation when a node leaves</span>
</div>
<div class="navheader">
<span class="prev">
<a href="shard-allocation-filtering.html">« Index-level shard allocation filtering</a>
</span>
<span class="next">
<a href="recovery-prioritization.html">Index recovery prioritization »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="delayed-allocation"></a>Delaying allocation when a node leaves<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/index-modules/allocation/delayed.asciidoc">edit</a>
</h2>
</div></div></div>
<p>When a node leaves the cluster for whatever reason, intentional or otherwise,
the master reacts by:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Promoting a replica shard to primary to replace any primaries that were on the node.
</li>
<li class="listitem">
Allocating replica shards to replace the missing replicas (assuming there are enough nodes).
</li>
<li class="listitem">
Rebalancing shards evenly across the remaining nodes.
</li>
</ul>
</div>
<p>These actions are intended to protect the cluster against data loss by
ensuring that every shard is fully replicated as soon as possible.</p>
<p>Even though we throttle concurrent recoveries both at the
<a class="xref" href="recovery.html" title="Index recovery settings">node level</a> and at the <a class="xref" href="shards-allocation.html" title="Cluster-level shard allocation">cluster level</a>, this
“shard-shuffle” can still put a lot of extra load on the cluster which
may not be necessary if the missing node is likely to return soon. Imagine
this scenario:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Node 5 loses network connectivity.
</li>
<li class="listitem">
The master promotes a replica shard to primary for each primary that was on Node 5.
</li>
<li class="listitem">
The master allocates new replicas to other nodes in the cluster.
</li>
<li class="listitem">
Each new replica makes an entire copy of the primary shard across the network.
</li>
<li class="listitem">
More shards are moved to different nodes to rebalance the cluster.
</li>
<li class="listitem">
Node 5 returns after a few minutes.
</li>
<li class="listitem">
The master rebalances the cluster by allocating shards to Node 5.
</li>
</ul>
</div>
<p>If the master had just waited for a few minutes, then the missing shards could
have been re-allocated to Node 5 with the minimum of network traffic.  This
process would be even quicker for idle shards (shards not receiving indexing
requests) which have been automatically <a class="xref" href="indices-synced-flush-api.html" title="Synced flush API">sync-flushed</a>.</p>
<p>The allocation of replica shards which become unassigned because a node has
left can be delayed with the <code class="literal">index.unassigned.node_left.delayed_timeout</code>
dynamic setting, which defaults to <code class="literal">1m</code>.</p>
<p>This setting can be updated on a live index (or on all indices):</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _all/_settings
{
  "settings": {
    "index.unassigned.node_left.delayed_timeout": "5m"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1032.console"></div>
<p>With delayed allocation enabled, the above scenario changes to look like this:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Node 5 loses network connectivity.
</li>
<li class="listitem">
The master promotes a replica shard to primary for each primary that was on Node 5.
</li>
<li class="listitem">
The master logs a message that allocation of unassigned shards has been delayed, and for how long.
</li>
<li class="listitem">
The cluster remains yellow because there are unassigned replica shards.
</li>
<li class="listitem">
Node 5 returns after a few minutes, before the <code class="literal">timeout</code> expires.
</li>
<li class="listitem">
The missing replicas are re-allocated to Node 5 (and sync-flushed shards recover almost immediately).
</li>
</ul>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>This setting will not affect the promotion of replicas to primaries, nor
will it affect the assignment of replicas that have not been assigned
previously. In particular, delayed allocation does not come into effect after a full cluster restart.
Also, in case of a master failover situation, elapsed delay time is forgotten
(i.e. reset to the full initial delay).</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_cancellation_of_shard_relocation"></a>Cancellation of shard relocation<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/index-modules/allocation/delayed.asciidoc">edit</a>
</h3>
</div></div></div>
<p>If delayed allocation times out, the master assigns the missing shards to
another node which will start recovery.  If the missing node rejoins the
cluster, and its shards still have the same sync-id as the primary, shard
relocation will be cancelled and the synced shard will be used for recovery
instead.</p>
<p>For this reason, the default <code class="literal">timeout</code> is set to just one minute: even if shard
relocation begins, cancelling recovery in favour of the synced shard is cheap.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_monitoring_delayed_unassigned_shards"></a>Monitoring delayed unassigned shards<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/index-modules/allocation/delayed.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The number of shards whose allocation has been delayed by this timeout setting
can be viewed with the <a class="xref" href="cluster-health.html" title="Cluster health API">cluster health API</a>:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET _cluster/health <a id="CO421-1"></a><i class="conum" data-value="1"></i></pre>
</div>
<div class="console_widget" data-snippet="snippets/1033.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO421-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>This request will return a <code class="literal">delayed_unassigned_shards</code> value.</p>
</td>
</tr>
</table>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_removing_a_node_permanently"></a>Removing a node permanently<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/index-modules/allocation/delayed.asciidoc">edit</a>
</h3>
</div></div></div>
<p>If a node is not going to return and you would like Elasticsearch to allocate
the missing shards immediately, just update the timeout to zero:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _all/_settings
{
  "settings": {
    "index.unassigned.node_left.delayed_timeout": "0"
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1034.console"></div>
<p>You can reset the timeout as soon as the missing shards have started to recover.</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="shard-allocation-filtering.html">« Index-level shard allocation filtering</a>
</span>
<span class="next">
<a href="recovery-prioritization.html">Index recovery prioritization »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>